/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MyNoteAppGUI.java
 *
 * Created on Apr 19, 2011, 3:57:04 PM
 */
package gui;

import business.MyNoteAppRead;
import business.MyNoteAppSave;
import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author spiegelverkehrt
 */
public class MyNoteAppGUI extends javax.swing.JFrame
{

    /** Creates new form MyNoteAppGUI */
    public MyNoteAppGUI()
    {
        initComponents();
        FcreateNote.setVisible(false);
    }
    private String seperate = "#";

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        FcreateNote = new javax.swing.JFrame();
        pnInfo = new javax.swing.JPanel();
        tfNoteTitle = new javax.swing.JTextField();
        cbNoteDateDay = new javax.swing.JComboBox();
        cbNoteDateMonth = new javax.swing.JComboBox();
        cbNoteDateYear = new javax.swing.JComboBox();
        pnNote = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        taNoteContent = new javax.swing.JTextArea();
        pnSave = new javax.swing.JPanel();
        btNoteSave = new javax.swing.JButton();
        fileChooser = new javax.swing.JFileChooser();
        pnOpenChooserLogo = new javax.swing.JPanel();
        lbMyNoteApp = new javax.swing.JLabel();
        pnOpenChooser = new javax.swing.JPanel();
        btOpenNote = new javax.swing.JButton();
        btCreateNote = new javax.swing.JButton();

        FcreateNote.setForeground(java.awt.Color.white);
        FcreateNote.setName("FcreateNote"); // NOI18N
        FcreateNote.setSize(new java.awt.Dimension(400, 500));

        pnInfo.setLayout(new java.awt.GridBagLayout());

        tfNoteTitle.setText("Sampel Note");
        tfNoteTitle.setBorder(javax.swing.BorderFactory.createTitledBorder("Title"));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
        pnInfo.add(tfNoteTitle, gridBagConstraints);

        cbNoteDateDay.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        pnInfo.add(cbNoteDateDay, gridBagConstraints);

        cbNoteDateMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }));
        cbNoteDateMonth.setSelectedIndex(11);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        pnInfo.add(cbNoteDateMonth, gridBagConstraints);

        cbNoteDateYear.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2010", "2011", "2012" }));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        pnInfo.add(cbNoteDateYear, gridBagConstraints);

        FcreateNote.getContentPane().add(pnInfo, java.awt.BorderLayout.NORTH);

        pnNote.setBorder(javax.swing.BorderFactory.createTitledBorder("Note"));
        pnNote.setLayout(new java.awt.BorderLayout());

        taNoteContent.setColumns(20);
        taNoteContent.setRows(5);
        jScrollPane2.setViewportView(taNoteContent);

        pnNote.add(jScrollPane2, java.awt.BorderLayout.CENTER);

        FcreateNote.getContentPane().add(pnNote, java.awt.BorderLayout.CENTER);

        pnSave.setPreferredSize(new java.awt.Dimension(400, 25));
        pnSave.setLayout(new java.awt.BorderLayout());

        btNoteSave.setText("Save");
        btNoteSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onNoteSave(evt);
            }
        });
        pnSave.add(btNoteSave, java.awt.BorderLayout.CENTER);

        FcreateNote.getContentPane().add(pnSave, java.awt.BorderLayout.SOUTH);

        fileChooser.setControlButtonsAreShown(false);
        fileChooser.setCurrentDirectory(null);
        fileChooser.setDialogTitle("Open Note");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("MyNoteApp");
        setForeground(java.awt.Color.white);
        setLocation(new java.awt.Point(250, 250));
        setName("FopenChooser"); // NOI18N

        lbMyNoteApp.setFont(new java.awt.Font("Papyrus", 1, 48)); // NOI18N
        lbMyNoteApp.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        lbMyNoteApp.setText("MyNoteApp");

        org.jdesktop.layout.GroupLayout pnOpenChooserLogoLayout = new org.jdesktop.layout.GroupLayout(pnOpenChooserLogo);
        pnOpenChooserLogo.setLayout(pnOpenChooserLogoLayout);
        pnOpenChooserLogoLayout.setHorizontalGroup(
            pnOpenChooserLogoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 439, Short.MAX_VALUE)
            .add(pnOpenChooserLogoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(pnOpenChooserLogoLayout.createSequentialGroup()
                    .add(0, 19, Short.MAX_VALUE)
                    .add(lbMyNoteApp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 400, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(0, 20, Short.MAX_VALUE)))
        );
        pnOpenChooserLogoLayout.setVerticalGroup(
            pnOpenChooserLogoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 200, Short.MAX_VALUE)
            .add(pnOpenChooserLogoLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(pnOpenChooserLogoLayout.createSequentialGroup()
                    .add(0, 0, Short.MAX_VALUE)
                    .add(lbMyNoteApp, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 200, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(0, 0, Short.MAX_VALUE)))
        );

        getContentPane().add(pnOpenChooserLogo, java.awt.BorderLayout.PAGE_START);

        pnOpenChooser.setLayout(new java.awt.GridLayout());

        btOpenNote.setText("Open Note");
        btOpenNote.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onOpenNote(evt);
            }
        });
        pnOpenChooser.add(btOpenNote);

        btCreateNote.setText("Create Note");
        btCreateNote.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                onCreateNote(evt);
            }
        });
        pnOpenChooser.add(btCreateNote);

        getContentPane().add(pnOpenChooser, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void onNoteSave(java.awt.event.ActionEvent evt)//GEN-FIRST:event_onNoteSave
    {//GEN-HEADEREND:event_onNoteSave
        String title = tfNoteTitle.getText();
        String date = String.valueOf(cbNoteDateDay.getSelectedItem()) + seperate + String.valueOf(cbNoteDateMonth.getSelectedItem()) + seperate + String.valueOf(cbNoteDateYear.getSelectedItem());
        String note = taNoteContent.getText();

        MyNoteAppSave mynoteapp = new MyNoteAppSave(title, date, note);
    }//GEN-LAST:event_onNoteSave

    private void onCreateNote(java.awt.event.ActionEvent evt)//GEN-FIRST:event_onCreateNote
    {//GEN-HEADEREND:event_onCreateNote
        FcreateNote.setVisible(true);
    }//GEN-LAST:event_onCreateNote

    private void onOpenNote(java.awt.event.ActionEvent evt)//GEN-FIRST:event_onOpenNote
    {//GEN-HEADEREND:event_onOpenNote
        String dateTemp;
        String[] splitDate = null;
        String day;
        String month;
        String year;

        int returnVal = fileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION)
        {
            File openNote = fileChooser.getSelectedFile();
            MyNoteAppRead readnote = new MyNoteAppRead(openNote);
            tfNoteTitle.setText(readnote.getValidTitle());

            dateTemp = readnote.getValidDate();
            
            splitDate = dateTemp.split(seperate);

            day = splitDate[0];
            month = splitDate[1];
            year = splitDate[2];

            cbNoteDateDay.setSelectedItem(day);
            cbNoteDateMonth.setSelectedItem(month);
            cbNoteDateYear.setSelectedItem(year);

            taNoteContent.setText(readnote.getValidNote());
            FcreateNote.setVisible(true);
        } else
        {
            System.out.println("File access cancelled by user.");
        }
    }//GEN-LAST:event_onOpenNote

    /**
     * @param args the command line arguments
     */
    public static void main(String args[])
    {
        java.awt.EventQueue.invokeLater(new Runnable() 
        
        
        
        {

            public void run()
            {
                new MyNoteAppGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame FcreateNote;
    private javax.swing.JButton btCreateNote;
    private javax.swing.JButton btNoteSave;
    private javax.swing.JButton btOpenNote;
    private javax.swing.JComboBox cbNoteDateDay;
    private javax.swing.JComboBox cbNoteDateMonth;
    private javax.swing.JComboBox cbNoteDateYear;
    private javax.swing.JFileChooser fileChooser;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lbMyNoteApp;
    private javax.swing.JPanel pnInfo;
    private javax.swing.JPanel pnNote;
    private javax.swing.JPanel pnOpenChooser;
    private javax.swing.JPanel pnOpenChooserLogo;
    private javax.swing.JPanel pnSave;
    private javax.swing.JTextArea taNoteContent;
    private javax.swing.JTextField tfNoteTitle;
    // End of variables declaration//GEN-END:variables
}
